# Contributor: Piper McCorkle <piper@cloudflare.com>
# Maintainer: Piper McCorkle <piper@cloudflare.com>
pkgname=cloudflared
pkgver=2022.3.1
pkgrel=3
pkgdesc="Cloudflare Tunnel client"
url="https://github.com/cloudflare/cloudflared"
arch="aarch64 x86 x86_64"
license="Apache-2.0"
makedepends="go gettext"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/cloudflare/cloudflared/archive/refs/tags/$pkgver.tar.gz"

build() {
	make cloudflared
	DATE="\"$(date -u '+%Y-%m-%d-%H%M UTC')\"" VERSION="$pkgver" envsubst < cloudflared_man_template > cloudflared.1
}

check() {
	_goarch=$(go tool dist env | grep GOARCH | sed 's/^GOARCH="//; s/"$//')
	# Go race detector is only supported on amd64, ppc64le, and arm64
	if [ $_goarch = "amd64" ] || [ $_goarch = "ppc64le" ] || [ $_goarch = "arm64" ]; then
		_race=-race
	fi
	go test -v -mod=vendor -buildmode=default $_race ./...
}

package() {
	install -D -m755 ./cloudflared "$pkgdir"/usr/bin/cloudflared
	install -D -m644 ./cloudflared.1 "$pkgdir"/usr/share/man/man1/cloudflared.1
}

sha512sums="
14c75b060cc5fbac7e56416bfb38bb90df4041903e220853e8aa3fffcbccbad65d9bdba4cdd8c16f185159298651a1932cca978bc514c7c390f3c40ebcce334e  cloudflared-2022.3.1.tar.gz
"
